package com.freewater.springboot.demo.publishevents;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;

import java.time.LocalDateTime;

@AllArgsConstructor
@Slf4j
public class OrderService {

    private ApplicationEventPublisher applicationEventPublisher;

    public void placeOrder(String orderId) {
        OrderPlacedEvent event = new OrderPlacedEvent(LocalDateTime.now(), orderId);
        this.applicationEventPublisher.publishEvent(event);
        log.info("order placed: {}", orderId);
    }
}
